<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								用户姓名：<input type="text" name="userName"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:integralOrder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:integralOrder:remove')}]];
		var detailFlag = [[${@permission.hasPermi('business:integralOrder:detail')}]];
		var cancelGoodsFlag = [[${@permission.hasPermi('business:integralOrder:cancelGoods')}]];
        var prefix = ctx + "business/integralOrder";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                detailUrl: prefix + "/detail/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "积分订单",
				search: false,
		        showExport: true,
                columns: [{
		            radio: true
		        },
				{
					field : 'orderId', 
					title : '积分订单',
					visible: false
				},
				{
					title: "序号",
					formatter: function (value, row, index) {
						return $.table.serialNumber(index);
					}
				},
				{
					field : 'orderNum',
					title : '订单号'
				},
				{
					field : 'userName',
					title : '用户姓名'
				},
				{
					field : 'integralGoods.goodsName',
					title : '商品信息 '
				},
				{
					field : 'exchangeCount', 
					title : '兑换数量',
					sortable: true
				},
				{
					field : 'payIntegral', 
					title : '积分支付',
					sortable: true
				},
				{
					field : 'exchangeTime', 
					title : '兑换时间',
					sortable: true
				},
				{
					field : 'exchangeStatus', 
					title : '兑换状态',
					formatter: function (value, row, index) {
						if (value == 0){
							return "未兑换"
						} else {
							return "已兑换"
						}
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
						actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="#" onclick="$.operate.detail(\'' + row.orderId + '\')"><i class="fa fa-search"></i> 详情</a> ');
						if (row.exchangeStatus == 0){
							actions.push('<a class="btn btn-success btn-xs ' + cancelGoodsFlag + '" href="#" onclick="cancelGoods(\'' + row.orderId + '\')"><i class="fa fa-edit"></i> 核销</a> ');
						}
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

		/**
		 * 核销兑换
		 * @param orderId
		 */
		function cancelGoods(orderId) {
			$.modal.open("核销商品",prefix+"/cancelGoodsPage/"+orderId,500,300)
		}
    </script>
</body>
</html>